﻿using System.Text;
using TVersityDotNet.HelperTypes;
using System.Globalization;
namespace TVersityDotNet.Requests
{
    /// <summary>
    /// Class representing a SettingsUpdate TVersityRequest
    /// </summary>
    public class SettingsUpdateRequest : TVersityRequest
    {
        private TVSettings _settings;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="settings">The TVersitySettings file to send off</param>
        public SettingsUpdateRequest(TVSettings settings)
        {
            this._settings = settings;
            base.Path = "settings/Update";            
        }

        /// <summary>
        /// Returns the whole string, minus the baseurl used to process this query
        /// </summary>
        public override string RequestString
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (string key in this._settings.PropertyBag.PropertiesWithValues.Keys)
                {
                    sb.AppendFormat("{0}={1}&", key, this._settings.PropertyBag.PropertiesWithValues[key]);
                }

                // Remove last &
                sb.Remove(sb.Length - 1, 1);
                return string.Format(CultureInfo.InvariantCulture, "{0}?{1}", this.Path, sb.ToString());
            }
        }
    }
}
